const http = require('http')
const fs = require('fs')
const path = require('path')

const server = http.createServer()
server.on('request', (req, res) => {
    let filename = ''
    const url = req.url;
    if (url === '/') {
        console.log('here');
        filename = path.join(__dirname, './index.html');
        console.log(filename);
    } else {
        filename = path.join(__dirname, url)
    }
    fs.readFile(filename, 'utf8', (err, str) => {
        if(err){
            res.setHeader('Content-Type', 'text/html; charset=utf-8')
            return res.end('404')
        }
        res.end(str)
    })
})
server.listen(80, () => {
    console.log('Server is running at http://localhost:8085');
})